package com.shsh.safemanage.model;

import java.io.Serializable;
import java.util.Calendar;

import com.shsh.safemanage.util.Constants;
import com.shsh.safemanage.util.MessageUtil;

public class Problem implements Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = 622412992194975681L;

	private Long id;
	private String problemTitle;
	private String problemContent;
	private String problemZhenggai;
	private Long department1ID;
	private String department1Name;
	private Long equipmentID;
	private String equipmentName;
	private Long writeUserID;
	private Calendar writeTime;
	private int processStatus;
	private String writeUserName;
	private Long transferID;
	private Long closeUserID;
	private String closeUserName;
	private Calendar closeTime;
	private boolean isNew;
	private Integer problemType;
	private Integer grade;
	private Long postcheckID;
	private String postcheckName;
	private Long postcheckPatternID;
	private Long postcheckContentID;
	private Long postcheckStandardID;
	private Calendar completeDate;
	private Long escalateDepart1ID;
	private Long writerManageGroupID;
	private String closeFeedback;
	private Long writerDepartment1ID;
	private String writerDepartment1Name;
	private int writerDepartmentType;
	private Long writerDepartment2ID;
	private String writerDepartment2Name;
	private Long writerDepartment3ID;
	private String writerDepartment3Name;
	private boolean isProcessingByChushi;
	private Boolean isSanwei;
	private boolean isSolved;
	private Boolean isClosed;
	private Long[] hseCategoryIDs;
	private String userTransferFeedbackStr;

	public static String getProblemName(Integer problemType) {
		switch (problemType) {
		case Constants.PROBLEM_TYPE_NOTPLANED_SHUTDOWN:
			return MessageUtil.getMessage(Constants.PROBLEM_NAME_NOTPLANNED_SHUTDOWN);
		case Constants.PROBLEM_TYPE_TEMP_SHUTDOWN:
			return MessageUtil.getMessage(Constants.PROBLEM_NAME_TEMP_SHUTDOWN);
		default:
			return null;
		}
	}

	public static String getTargetDetailedPageURL(Problem problem, String contextPath) {
		Integer problemType = problem.getProblemType();
		if (problemType == null || problemType.equals(0)) {
			return contextPath + "/problem_feedback.jsp";
		} else if (Constants.PROBLEM_TYPE_DEFECT == problemType.intValue()) {
			return contextPath + "/defect/defect_feedback.jsp";
		} else if (Constants.PROBLEM_TYPE_OTHER == problemType.intValue()) {
			return contextPath + "/other/other_feedback.jsp";
		} else if (Constants.PROBLEM_TYPE_TENDENCY == problemType.intValue()) {
			return contextPath + "/tendency/tendency_feedback.jsp";
		} else if (Constants.PROBLEM_TYPE_NOTPLANED_SHUTDOWN == problemType.intValue()
				|| Constants.PROBLEM_TYPE_TEMP_SHUTDOWN == problemType.intValue()) {
			return contextPath + "/shutdown/shutdown_feedback.jsp?problemType=" + problemType.intValue();
		} else if (Constants.PROBLEM_TYPE_ACCIDENT_REGISTERFORM == problemType.intValue()
				|| Constants.PROBLEM_TYPE_ACCIDENT_INFOSHEET == problemType.intValue()
				|| Constants.PROBLEM_TYPE_ACCIDENT_REPORT == problemType.intValue()
				|| Constants.PROBLEM_TYPE_ACCIDENT_CHECKFORM2 == problemType.intValue()
				|| Constants.PROBLEM_TYPE_ACCIDENT_CHECKFORM3 == problemType.intValue()) {
			return contextPath + "/accident/application_table_problem.jsp";
		} else if (Constants.PROBLEM_TYPE_POSTCHECK_MONTH_CHECK_REPORT == problemType.intValue()) {
			if (problem.getCloseUserID() != null) {
				return contextPath + "/postcheck/report/read_depart_month_check.jsp";
			} else {
				return contextPath + "/postcheck/report/feedback_depart_month_check.jsp";
			}
		} else if (Constants.PROBLEM_TYPE_POSTCHECK_MONTH_SANWEI_REPORT == problemType.intValue()) {
			if (problem.getCloseUserID() != null) {
				return contextPath + "/postcheck/report/read_depart_month_sanwei.jsp";
			} else {
				return contextPath + "/postcheck/report/feedback_depart_month_sanwei.jsp";
			}
		} else if (Constants.PROBLEM_TYPE_POSTCHECK_MONTH_CORPSANWEI_REPORT == problemType.intValue()) {
			if (problem.getCloseUserID() != null) {
				return contextPath + "/postcheck/report/read_corp_month_sanwei.jsp";
			} else {
				return contextPath + "/postcheck/report/feedback_corp_month_sanwei.jsp";
			}
		} else if (Constants.PROBLEM_TYPE_WEAK_REPORT == problemType.intValue()) {
			return contextPath + "/weak/feedback_report.jsp";
		} else {
			return contextPath + "/problem_feedback.jsp";
		}
	}

	public Problem() {

	}

	public Problem(Problem problem) {
		this.copy(problem);
	}

	public String getWriterDepartment1Name() {
		return writerDepartment1Name;
	}

	public void setWriterDepartment1Name(String writerDepartment1Name) {
		this.writerDepartment1Name = writerDepartment1Name;
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getProblemTitle() {
		return problemTitle;
	}

	public void setProblemTitle(String problemTitle) {
		this.problemTitle = problemTitle;
	}

	public String getProblemContent() {
		return problemContent;
	}

	public String getProblemContent(int len) {
		if (this.problemContent == null) {
			return "";
		}
		if (this.problemContent.length() <= len) {
			return this.problemContent;
		} else {
			return this.problemContent.substring(0, len) + "...";
		}
	}

	public void setProblemContent(String problemContent) {
		this.problemContent = problemContent;
	}

	public String getProblemZhenggai() {
		return problemZhenggai;
	}

	public String getProblemZhenggai(int len) {
		if (this.problemZhenggai.length() <= len) {
			return this.problemZhenggai;
		} else {
			return this.problemZhenggai.substring(0, len) + "...";
		}
	}

	public void setProblemZhenggai(String problemZhenggai) {
		this.problemZhenggai = problemZhenggai;
	}

	public Long getDepartment1ID() {
		return department1ID;
	}

	public void setDepartment1ID(Long department1id) {
		department1ID = department1id;
	}

	public Long getEquipmentID() {
		return equipmentID;
	}

	public void setEquipmentID(Long equipmentID) {
		this.equipmentID = equipmentID;
	}

	public Long getWriteUserID() {
		return writeUserID;
	}

	public void setWriteUserID(Long writeUserID) {
		this.writeUserID = writeUserID;
	}

	public Calendar getWriteTime() {
		return writeTime;
	}

	public void setWriteTime(Calendar writeTime) {
		this.writeTime = writeTime;
	}

	public int getProcessStatus() {
		return processStatus;
	}

	public void setProcessStatus(int processStatus) {
		this.processStatus = processStatus;
	}

	public String getWriteUserName() {
		return writeUserName == null ? "" : writeUserName;
	}

	public void setWriteUserName(String writeUserName) {
		this.writeUserName = writeUserName;
	}

	public String getDepartment1Name() {
		return department1Name;
	}

	public Boolean isSanwei() {
		return isSanwei;
	}

	public boolean isSolved() {
		return isSolved;
	}

	public void setSolved(boolean isSolved) {
		this.isSolved = isSolved;
	}

	public void setSanwei(Boolean isSanwei) {
		this.isSanwei = isSanwei;
	}

	public void setDepartment1Name(String department1Name) {
		this.department1Name = department1Name;
	}

	public String getEquipmentName() {
		return equipmentName;
	}

	public void setEquipmentName(String equipmentName) {
		this.equipmentName = equipmentName;
	}

	public Long getTransferID() {
		return transferID;
	}

	public void setTransferID(Long transferID) {
		this.transferID = transferID;
	}

	public Calendar getCloseTime() {
		return closeTime;
	}

	public void setCloseTime(Calendar closeTime) {
		this.closeTime = closeTime;
	}

	public Long getCloseUserID() {
		return closeUserID;
	}

	public Long getWriterManageGroupID() {
		return writerManageGroupID;
	}

	public void setWriterManageGroupID(Long writerManageGroupID) {
		this.writerManageGroupID = writerManageGroupID;
	}

	public Long getEscalateDepart1ID() {
		return escalateDepart1ID;
	}

	public String getWriterDepartment2Name() {
		return writerDepartment2Name;
	}

	public void setWriterDepartment2Name(String writerDepartment2Name) {
		this.writerDepartment2Name = writerDepartment2Name;
	}

	public Long getWriterDepartment3ID() {
		return writerDepartment3ID;
	}

	public void setWriterDepartment3ID(Long writerDepartment3ID) {
		this.writerDepartment3ID = writerDepartment3ID;
	}

	public String getWriterDepartment3Name() {
		return writerDepartment3Name;
	}

	public void setWriterDepartment3Name(String writerDepartment3Name) {
		this.writerDepartment3Name = writerDepartment3Name;
	}

	public void setEscalateDepart1ID(Long escalateDepart1ID) {
		this.escalateDepart1ID = escalateDepart1ID;
	}

	public boolean isNew() {
		return isNew;
	}

	public void setNew(boolean isNew) {
		this.isNew = isNew;
	}

	public void setCloseUserID(Long closeUserID) {
		this.closeUserID = closeUserID;
	}

	public boolean equals(Object o) {
		if (o == null) {
			return false;
		}

		if (!(o instanceof Problem)) {
			return false;
		}

		Problem problem = (Problem) o;
		return this.id.equals(problem.getId());
	}

	public int hashCode() {
		return this.id.intValue();
	}

	public int nextStatus(int next) {
		if (this.getProcessStatus() == Constants.PROBLEM_STATUS_OPEN) {
			if (next > 0) {
				return Constants.PROBLEM_STATUS_ZUZHANG_ZHUANGZHIZHANG;
			} else {
				return Constants.PROBLEM_STATUS_OPEN;
			}
		} else if (this.getProcessStatus() == Constants.PROBLEM_STATUS_ZUZHANG_ZHUANGZHIZHANG) {
			if (next > 0) {
				return Constants.PROBLEM_STATUS_ANQUANZONGJIAN_FUBUZHANG;
			} else {
				return Constants.PROBLEM_STATUS_ZUYUAN;
			}
		} else if (this.getProcessStatus() == Constants.PROBLEM_STATUS_ANQUANZONGJIAN_FUBUZHANG) {
			if (next > 0) {
				return Constants.PROBLEM_STATUS_BUZHANG;
			} else {
				return Constants.PROBLEM_STATUS_ZUZHANG_ZHUANGZHIZHANG;
			}
		} else if (this.getProcessStatus() == Constants.PROBLEM_STATUS_BUZHANG) {
			if (next > 0) {
				return Constants.PROBLEM_STATUS_BUZHANG;
			} else {
				return Constants.PROBLEM_STATUS_ANQUANZONGJIAN_FUBUZHANG;
			}
		}

		return Constants.PROBLEM_STATUS_OPEN;
	}

	public Integer getProblemType() {
		return problemType;
	}

	public void setProblemType(Integer problemType) {
		this.problemType = problemType;
	}

	public Integer getGrade() {
		return grade;
	}

	public void setGrade(Integer grade) {
		this.grade = grade;
	}

	public Long getPostcheckID() {
		return postcheckID;
	}

	public void setPostcheckID(Long postcheckID) {
		this.postcheckID = postcheckID;
	}

	public Calendar getCompleteDate() {
		return completeDate;
	}

	public void setCompleteDate(Calendar completeDate) {
		this.completeDate = completeDate;
	}

	public Long getPostcheckPatternID() {
		return postcheckPatternID;
	}

	public void setPostcheckPatternID(Long postcheckPatternID) {
		this.postcheckPatternID = postcheckPatternID;
	}

	public Long getPostcheckContentID() {
		return postcheckContentID;
	}

	public void setPostcheckContentID(Long postcheckContentID) {
		this.postcheckContentID = postcheckContentID;
	}

	public Long getPostcheckStandardID() {
		return postcheckStandardID;
	}

	public void setPostcheckStandardID(Long postcheckStandardID) {
		this.postcheckStandardID = postcheckStandardID;
	}

	public String getCloseUserName() {
		return closeUserName == null ? "" : closeUserName;
	}

	public void setCloseUserName(String closeUserName) {
		this.closeUserName = closeUserName;
	}

	public String getCloseFeedback() {
		return closeFeedback;
	}

	public void setCloseFeedback(String closeFeedback) {
		this.closeFeedback = closeFeedback;
	}

	public String getPostcheckName() {
		return postcheckName;
	}

	public void setPostcheckName(String postcheckName) {
		this.postcheckName = postcheckName;
	}

	public Long getWriterDepartment1ID() {
		return writerDepartment1ID;
	}

	public void setWriterDepartment1ID(Long writerDepartment1ID) {
		this.writerDepartment1ID = writerDepartment1ID;
	}

	public Long getWriterDepartment2ID() {
		return writerDepartment2ID;
	}

	public void setWriterDepartment2ID(Long writerDepartment2ID) {
		this.writerDepartment2ID = writerDepartment2ID;
	}

	public int getWriterDepartmentType() {
		return writerDepartmentType;
	}

	public void setWriterDepartmentType(int writerDepartmentType) {
		this.writerDepartmentType = writerDepartmentType;
	}

	public boolean isProcessingByChushi() {
		return isProcessingByChushi;
	}

	public void setProcessingByChushi(boolean isProcessingByChushi) {
		this.isProcessingByChushi = isProcessingByChushi;
	}

	public Boolean getIsSanwei() {
		return isSanwei;
	}

	public void setIsSanwei(Boolean isSanwei) {
		this.isSanwei = isSanwei;
	}

	public Long[] getHseCategoryIDs() {
		return hseCategoryIDs;
	}

	public void setHseCategoryIDs(Long[] hseCategoryIDs) {
		this.hseCategoryIDs = hseCategoryIDs;
	}

	public Boolean getIsClosed() {
		return isClosed;
	}

	public void setIsClosed(Boolean isClosed) {
		this.isClosed = isClosed;
	}

	public String getUserTransferFeedbackStr() {
		return userTransferFeedbackStr;
	}

	public void setUserTransferFeedbackStr(String userTransferFeedbackStr) {
		this.userTransferFeedbackStr = userTransferFeedbackStr;
	}

	private void copy(Problem problem) {
		setCloseTime(problem.getCloseTime());
		setCloseUserID(problem.getCloseUserID());
		setCloseUserName(problem.getCloseUserName());
		setCompleteDate(problem.getCompleteDate());
		setDepartment1ID(problem.getDepartment1ID());
		setDepartment1Name(problem.getDepartment1Name());
		setEquipmentID(problem.getEquipmentID());
		setEquipmentName(problem.getEquipmentName());
		setEscalateDepart1ID(problem.getEscalateDepart1ID());
		setGrade(problem.getGrade());
		setId(problem.getId());
		setNew(problem.isNew());
		setPostcheckContentID(problem.getPostcheckContentID());
		setPostcheckID(problem.getPostcheckID());
		setPostcheckPatternID(problem.getPostcheckPatternID());
		setPostcheckStandardID(problem.getPostcheckStandardID());
		setProblemContent(problem.getProblemContent());
		setProblemTitle(problem.getProblemTitle());
		setProblemType(problem.getProblemType());
		setProblemZhenggai(problem.getProblemZhenggai());
		setProcessStatus(problem.getProcessStatus());
		setTransferID(problem.getTransferID());
		setWriterManageGroupID(problem.getWriterManageGroupID());
		setWriteTime(problem.getWriteTime());
		setWriteUserID(problem.getWriteUserID());
		setWriteUserName(problem.getWriteUserName());

		postcheckName = problem.getPostcheckName();
		closeFeedback = problem.getCloseFeedback();
		writerDepartment1ID = problem.getWriterDepartment1ID();
		writerDepartment1Name = problem.getWriterDepartment1Name();
		writerDepartment2ID = problem.getWriterDepartment2ID();
		isSolved = problem.isSolved();
		isSanwei = problem.isSanwei();
		hseCategoryIDs = problem.getHseCategoryIDs();
		isClosed = problem.getIsClosed();
		userTransferFeedbackStr = problem.getUserTransferFeedbackStr();
	}
}
